#pragma once

#include <rviz_common/panel.hpp>
#include <rviz_common/config.hpp>
#include <QMutex>
#include <QImage>
#include <QString>
#include <rviz_common/ros_integration/ros_node_abstraction_iface.hpp>
#include <controller_msgs/msg/visbot_id_box_arr.hpp>
#include <rviz_default_plugins/visibility_control.hpp>
#include "rviz_custom_plugins/widgets/video_widget.h"
#include "rviz_custom_plugins/utils/widget_manager.h"


using rviz_custom_plugins::utils::WidgetManager;
using rviz_common::Panel;
using rviz_common::Config;
using rviz_custom_plugins::widgets::VideoWidget;
using controller_msgs::msg::VisbotIDBoxArr;


namespace rviz_custom_plugins {


namespace panels {


class RVIZ_DEFAULT_PLUGINS_PUBLIC VideoPanel : public Panel 
{
    Q_OBJECT
    
public:
    explicit VideoPanel(QWidget *parent = nullptr);
    VideoWidget* getVideoWidget();

    void onInitialize() override;
    void save(Config config) const override;
    void load(const Config& config) override;

private:
    VideoWidget* videoWidget;
    QPointer<WidgetManager> widgetManager;
    rviz_common::ros_integration::RosNodeAbstractionIface::WeakPtr rosNode;
    rclcpp::Subscription<VisbotIDBoxArr>::SharedPtr subscriptionPtr;

    void subscribe(QString topic);
    void unsubscribe();
    void processMessage(const VisbotIDBoxArr::ConstSharedPtr message);

private slots:
    void handleWidgetShow(int widgetId, bool isShow);

};


}


}


